﻿/*----------------------------------------------------------------
    // Copyright (C) 2009 江苏华招网
    // 版权所有。 
    // 作者：董辉
    //
    // 文件名：HospitalCover.cs
    // 文件功能描述：配送企业配送能力查询统计
    // 创建标识：董辉 2011-3-29 10:39
    //
    // 修改标识：
    // 修改描述：
    //
    // 修改标识：
    // 修改描述：
    //
    // 审核人：
    // 审核时间：
    // 审核说明：
 //----------------------------------------------------------------*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HZ.Supervise.Model.Enum;

namespace HZ.Supervise.Web.Company
{
	public partial class HospitalCover : BasePage
	{
		HZ.Supervise.IBLL.IExecuteContext ibll = HZ.Supervise.BLLFactory.ExecuteContext();

		public HospitalCover()
		{
			this.ModuleNo = Module.企业统计分析.ToString();
			this.PageOperateType = OperateType.配送企业配送能力统计.ToString();
		}

		protected void Page_Load(object sender, EventArgs e)
		{
			this.hidAreaId.Value = CurrentAccount.GetUser().Org.Area.AreaID;//把用户的areaid赋给隐藏字段保存

			if (!IsPostBack)
			{
                //结束时间
                txtendtime.Text = DateTime.Now.ToShortDateString();

                //开始时间
                txtstarttime.Text = "2011-10-24";

				//绑定数据
				CompanyDataBind();
			}
		}

		/// <summary>
		/// 绑定数据
		/// 董辉
		/// 2011-3-29 10:58
		/// </summary>
		private void CompanyDataBind()
		{
			try
			{

				System.Text.StringBuilder whereAreaId = new System.Text.StringBuilder();

				if (this.hidAreaId.Value != Constants.CURRENT_DEPLOY_AREAID)
				{

					if (this.hidAreaId.Value.Substring(4, 2) == "00")//市级
					{

						whereAreaId.AppendFormat(" and areaid like '{0}%'", this.hidAreaId.Value.Substring(0, 4));

					}
					else
					{

						whereAreaId.AppendFormat(" and areaid = '{0}'", this.hidAreaId.Value);

					}

				}
				else
				{

					whereAreaId.Append(" and 1=1");

				}


				DateTime start = Convert.ToDateTime(txtstarttime.Text);

				DateTime end = Convert.ToDateTime(txtendtime.Text);

				if (end < start)
				{
					HZ.Web.WebUtil.Alert("后置时间不能小于前置时间！");
				}
				else
				{
					int t = 0;

					System.Data.DataTable dt = ibll.GetHospitalCover(whereAreaId.ToString(),txtstarttime.Text, txtendtime.Text, 1, 0, out t);

					this.gv.DataSource = dt;

					HZ.Supervise.Web.Function.ChangeRate_PS(dt, "Rate");

					this.gv.DataBind();
				}
			}
			catch (Exception e)
			{
				e.ToString();

				HZ.Web.WebUtil.Alert("时间格式输入错误！");
			}
		}

		/// <summary>
		/// 查询数据事件
		/// 董辉
		/// 2011-3-29 10:38
		/// </summary>
		/// <param name="sender">事件发送源</param>
		/// <param name="e">事件参数</param>
		protected void btnQuery_Click(object sender, EventArgs e)
		{
			//重新绑定数据
			CompanyDataBind();
		}

		/// <summary>
		/// 导出数据事件
		/// 董辉
		/// 2011-3-29 10:43
		/// </summary>
		/// <param name="sender">事件发送源</param>
		/// <param name="e">事件参数</param>
		protected void btnExcel_Click(object sender, EventArgs e)
		{
			try
			{
				System.Text.StringBuilder whereAreaId = new System.Text.StringBuilder();
				if (this.hidAreaId.Value != Constants.CURRENT_DEPLOY_AREAID)
				{

					if (this.hidAreaId.Value.Substring(4, 2) == "00")//市级
					{

						whereAreaId.AppendFormat(" and areaid like '{0}%'", this.hidAreaId.Value.Substring(0, 4));

					}
					else
					{

						whereAreaId.AppendFormat(" and areaid = '{0}'", this.hidAreaId.Value);

					}

				}
				else
				{

					whereAreaId.Append(" and 1=1");

				}

				DateTime start = Convert.ToDateTime(txtstarttime.Text);

				DateTime end = Convert.ToDateTime(txtendtime.Text);

				if (end < start)
				{
					HZ.Web.WebUtil.Alert("后置时间不能小于前置时间！");
				}
				else
				{
					int t = 0;

					System.Data.DataTable dt = ibll.GetHospitalCover(whereAreaId.ToString(),txtstarttime.Text, txtendtime.Text, 0, 0, out t);

					HZ.Supervise.Web.Function.ChangeRate_PS(dt, "Rate");

					//ExportFile.Instance.ExportData(dt, gv, this.Page);

					HZ.Excel.ExcelHelper.ExportDataForWeb(dt, gv);
				}
			}
			catch (Exception e1)
			{
				e1.ToString();

				HZ.Web.WebUtil.Alert("时间格式输入错误！");
			}
		}
	}
}
